# Copyright 2019 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load(
    "//build_tools/bazel:build_defs.oss.bzl",
    "iree_compiler_cc_library",
    "iree_gentbl_cc_library",
    "iree_tablegen_doc",
)

package(
    default_visibility = ["//visibility:public"],
    features = ["layering_check"],
    licenses = ["notice"],  # Apache 2.0
)

iree_compiler_cc_library(
    name = "Transforms",
    srcs = [
        "AnnotateTargetDevices.cpp",
        "AssignLegacyTargetDevices.cpp",
        "AssignTargetDevices.cpp",
        "CaptureExecutableSources.cpp",
        "ConfigureExecutables.cpp",
        "ConvertToHAL.cpp",
        "DumpExecutableBenchmarks.cpp",
        "DumpExecutableSources.cpp",
        "ElideRedundantCommands.cpp",
        "HoistExecutableObjects.cpp",
        "InitializeDevices.cpp",
        "InlineMemoizeRegions.cpp",
        "LinkExecutables.cpp",
        "MaterializeDispatchInstrumentation.cpp",
        "MaterializeInterfaces.cpp",
        "MaterializeResourceCaches.cpp",
        "MaterializeTargetDevices.cpp",
        "MemoizeDeviceQueries.cpp",
        "MemoizeDeviceSelection.cpp",
        "OutlineMemoizeRegions.cpp",
        "Passes.cpp",
        "Passes.h.inc",
        "PreprocessExecutables.cpp",
        "PruneExecutables.cpp",
        "RepeatDispatches.cpp",
        "ResolveDeviceAliases.cpp",
        "ResolveDevicePromises.cpp",
        "ResolveExportOrdinals.cpp",
        "ResolveTopologyQueries.cpp",
        "SerializeExecutables.cpp",
        "StripExecutableContents.cpp",
        "SubstituteExecutables.cpp",
        "TranslateExecutables.cpp",
        "VerifyDevices.cpp",
    ],
    hdrs = [
        "Passes.h",
    ],
    deps = [
        ":PassesIncGen",
        "//compiler/src/iree/compiler/Codegen/Dialect/Codegen/IR:IREECodegenDialect",
        "//compiler/src/iree/compiler/Dialect/Flow/IR",
        "//compiler/src/iree/compiler/Dialect/HAL/Analysis",
        "//compiler/src/iree/compiler/Dialect/HAL/Conversion",
        "//compiler/src/iree/compiler/Dialect/HAL/Conversion/HALToHAL",
        "//compiler/src/iree/compiler/Dialect/HAL/Conversion/StandardToHAL",
        "//compiler/src/iree/compiler/Dialect/HAL/Conversion/StreamToHAL",
        "//compiler/src/iree/compiler/Dialect/HAL/Conversion/StreamToHAL:Utils",
        "//compiler/src/iree/compiler/Dialect/HAL/Conversion/UtilToHAL",
        "//compiler/src/iree/compiler/Dialect/HAL/IR",
        "//compiler/src/iree/compiler/Dialect/HAL/IR:HALDialect",
        "//compiler/src/iree/compiler/Dialect/HAL/Target",
        "//compiler/src/iree/compiler/Dialect/HAL/Target/Devices",
        "//compiler/src/iree/compiler/Dialect/Stream/IR",
        "//compiler/src/iree/compiler/Dialect/Stream/Transforms",
        "//compiler/src/iree/compiler/Dialect/Util/Conversion",
        "//compiler/src/iree/compiler/Dialect/Util/IR",
        "//compiler/src/iree/compiler/Dialect/Util/Transforms",
        "//compiler/src/iree/compiler/Modules/IO/Parameters/IR:IOParametersDialect",
        "//compiler/src/iree/compiler/Utils",
        "//runtime/src/iree/schemas/instruments",
        "//runtime/src/iree/schemas/instruments:dispatch_def_c_fbs",
        "@llvm-project//llvm:Support",
        "@llvm-project//mlir:AffineToStandard",
        "@llvm-project//mlir:AffineTransforms",
        "@llvm-project//mlir:ArithDialect",
        "@llvm-project//mlir:AsmParser",
        "@llvm-project//mlir:BufferizationDialect",
        "@llvm-project//mlir:ControlFlowDialect",
        "@llvm-project//mlir:FuncDialect",
        "@llvm-project//mlir:FunctionInterfaces",
        "@llvm-project//mlir:IR",
        "@llvm-project//mlir:Parser",
        "@llvm-project//mlir:Pass",
        "@llvm-project//mlir:SCFDialect",
        "@llvm-project//mlir:SCFToControlFlow",
        "@llvm-project//mlir:Support",
        "@llvm-project//mlir:TensorDialect",
        "@llvm-project//mlir:TransformUtils",
        "@llvm-project//mlir:Transforms",
    ],
)

iree_gentbl_cc_library(
    name = "PassesIncGen",
    tbl_outs = [
        (
            ["--gen-pass-decls"],
            "Passes.h.inc",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "Passes.td",
    deps = [
        "@llvm-project//mlir:PassBaseTdFiles",
    ],
)

iree_tablegen_doc(
    name = "HALPassesDocGen",
    category = "Passes",
    tbl_outs = [
        (
            [
                "--gen-pass-doc",
            ],
            "HALPasses.md",
        ),
    ],
    tblgen = "@llvm-project//mlir:mlir-tblgen",
    td_file = "Passes.td",
    deps = [
        "@llvm-project//mlir:PassBaseTdFiles",
    ],
)
